package com.qidian.common;

import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.PropertyConfigurator;

public final class Constants 
{
	static Properties p = new Properties();
	public static boolean DEBUG = false ;
	static{
		PropertyConfigurator.configure(Constants.class.getClassLoader().getResource("log4j.properties"));
	
    	try {
			InputStream configInputStream = Constants.class.getClassLoader().getResourceAsStream("config.properties");
			p.load(configInputStream) ;
			configInputStream.close() ;
		} catch (Exception e) {
			e.printStackTrace();
		}
		DEBUG = "true".equalsIgnoreCase(p.getProperty("Debug"));
	}
	
	public static String splitString = "#" ;
	public static String ROOTPATH  = "./" ;
	
	// 媒体对象的最大上传尺寸:64KB
	public static int maxUploadSize = 64*1024 ;
	
	//允许的最大、最小回答时间间隔，单位为秒
	public static int min_interval = 15 ;
	public static int max_interval = 200 ;
	public static int default_interval = 30 ;
	
	// 判定客户端僵死的最大时间间隔
	public static int ZombieInterval = 60;
	
	// Socket 缓冲区
	public static int socket_buf_size = 64*1024;
	public static int socket_time_out = 3000 ;// 不宜太小，太小导致发送文件由于连接超时导致失败的概率增加
	public static int file_server_num_threads = 20 ;
	
	// 客户端每次答题的最大数量
	public static int max_msg_per_request = 4;
	public static int max_msg_local = 2 ;
	public static int trans_threshold = Integer.parseInt(p.getProperty("trans_threshold","15"));
	public static int interval_split_1 =Integer.parseInt(p.getProperty("interval_split_1", "30")) ;
	public static int interval_split_2 =Integer.parseInt(p.getProperty("interval_split_2", "70")) ;
	
	public static String answer_charset = "GBK" ;
	
	// 消息存在于缓冲区中的最大时间，单位为秒
	public static int timeToSync = 200 ;
	// 消息存在于数据库中的最大时间，单位为毫秒，默认为3天
	public static long message_keep_time = 3*24*60*60*1000L ;
	
	// 最小点数,
	public static int min_points = 100 ;
	public static int max_points = 100000000 ;
	
	// 有效期最大天数10000天，最小天数1
	public static long max_day_validity = 10000 ;
	public static long min_day_validity = 1 ;
	public static long millseconds_per_day = 24L*60*60*1000 ;
	public static long millseconds_per_year = 365L*24*60*60*1000 ;
	
	public static double point_ratio_00_08 = 1.25 ;
	public static double point_ratio_08_16 = 1.0 ;
	public static double point_ratio_16_24 = 1.0 ; 
	public static volatile double point_ratio_current = point_ratio_00_08 ;
	
	// 误报扣点比率
	public static double ratio_report_wrong = 2.0 ;
	
	// 最大批量数
	public static int max_batch_size = 1000 ;
	// 用户每天可生成的最大子帐号、冲值卡数量
	public static int max_account_per_day = 10000 ;
	public static int max_recharge_card_per_day = 10000 ;
	
	// 多余点数分成
	public static double extra_return_ratio = Double.parseDouble(p.getProperty("extra_return_ratio")) ;
	
	// 超级用户用户名
	public static String super_user_name = "root_mserver" ;
	public static String super_password  = "pwd_mserver" ;
	public static String super_qq = "281888722" ;
	public static String super_email = "281888722@qq.com" ;
	public static String return_user_name = "admin360" ;
	public static double init_return_ratio = 0.30 ;
	public static String key = "qidian360" ;
	
	// 服务器信息
	public static int portSendFile = Integer.parseInt(p.getProperty("portSendFile")) ;
	public static int portGetAnswer = Integer.parseInt(p.getProperty("portGetAnswer")) ;
	public static int portOthers = Integer.parseInt(p.getProperty("portOthers")) ;
	public static int portSysInfo = Integer.parseInt(p.getProperty("portSysInfo")) ;
	public static int portHttp = Integer.parseInt(p.getProperty("portHttp")) ;
	public static int portSysInfoHttp = 8889 ;
	public static String protocol = p.getProperty("protocol") ;
	public static String localIP = p.getProperty("localIP") ;
	public static String localIP_CTC = p.getProperty("localIP_CTC") ;
	public static String localIP_CUCC = p.getProperty("localIP_CUCC") ;
	public static String localIP_CMCC = p.getProperty("localIP_CMCC") ;
	public static String localIP_OTHER = p.getProperty("localIP_OTHER") ;
//	public static String hostServer = p.getProperty("hostServer") ;
	public static String hostURL = p.getProperty("hostURL") ;
	public static String hostServerBackup = p.getProperty("hostServer_backup") ;
//	public static String hostURLBackup = p.getProperty("hostURL_backup") ;
	public static String ip_sysinfo = p.getProperty("ip_sysinfo") ;
	public static String ip_sysinfo_backup = p.getProperty("ip_sysinfo_back") ;
	public static boolean startSysInfoServer = "true".equalsIgnoreCase(p.getProperty("startSysInfoServer"));
	
	public static boolean needUpdateOldSysInfoServer = "true".equalsIgnoreCase(p.getProperty("needUpdateOldSysInfoServer"));
	public static String ip_sysinfo_old_1 = p.getProperty("ip_sysinfo_old_1") ;
	public static String ip_sysinfo_old_2 = p.getProperty("ip_sysinfo_old_2") ;
	
	// 线程池
	public static int num_threads_get_answer = 15 ;
	public static int num_threads_send_file = 15 ;
	public static int num_threads_system_info = 5 ;
	
	public static String taobao_url = "http://shop36264161.taobao.com/shop/view_shop.htm" +
			"?spm=a1z09.1.0.275.fCpJya&mytmenu=mdianpu" +
			"&utkn=g,wkumr7ou2o57lnpk1358089010119&user_number_id=64048573&scm=1028.1.2.20001" ;
	
	public static void updateClientPointRatio()
	{
		java.sql.Timestamp time = new java.sql.Timestamp(System.currentTimeMillis()) ;
		int curHour = time.getHours() ;
		if (curHour >= 0 && curHour<8)
			point_ratio_current = point_ratio_00_08 ;
		else if (curHour >=8 && curHour < 16)
			point_ratio_current = point_ratio_08_16 ;
		else
			point_ratio_current= point_ratio_16_24 ;
	}
}
